package com.retrofit.rxjava;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.cjt2325.cameralibrary.util.LogUtil;
import com.cjt2325.cameraview.R;
import com.google.gson.JsonObject;
import com.retrofix.BaseObserver;
import com.retrofix.ObservableLoader;
import com.retrofix.RetrofitFactory;
import com.retrofix.entity.ABean;
import com.retrofix.entity.BaseEntity;
import com.retrofix.entity.TestBean;

import org.json.JSONObject;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitActivity extends AppCompatActivity {
    Button button1;

    public static final String BASE_URL = "https://api.douban.com/v2/movie/";
    public static final int DEFAULT_TIME_OUT = 30;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_retrofit);

        button1 = (Button) findViewById(R.id.getRequest);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObservableLoader.observe(RetrofitFactory.getInstence().API().getTestData(1))
                        .subscribe(new BaseObserver<List<TestBean>>() {

                            @Override
                            protected void onSuccess(BaseEntity<List<TestBean>> t) throws Exception {
                                String ss = t.getMsg();
                            }

                            @Override
                            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                                String ss = e.getMessage();
                            }
                        });
            }
        });
    }


}
